
using System;
using System.Collections;
using System.Web.UI.WebControls;

namespace GiftNet.Model
{
	#region StockPosition Model -(by fangyifeng at 2013-11-04 11:24:47)

	/// <summary>
	/// StockPosition object'StockPosition'.
	/// </summary>
    [Serializable]
	public class StockPosition : System.IComparable
		{
		#region Member Variables
		
		protected Guid _id;
		protected string _sPCode;
		protected string _sPMemo;
		protected short _sPOrder;
		
		protected static String _sortExpression = "Id";
		protected static SortDirection _sortDirection = SortDirection.Ascending;

		#endregion

		#region Constructors

		public StockPosition() { }

		public StockPosition( string sPCode, string sPMemo, short sPOrder)
		{
			this._sPCode = sPCode;
			this._sPMemo = sPMemo;
			this._sPOrder = sPOrder;
		}

		#endregion

		#region Public Properties

		public virtual Guid Id
		{
			get {return _id;}
			set {_id = value;}
		}

		public virtual string SPCode
		{
			get { return _sPCode; }
			set
			{
				if ( value != null && value.Length > 50)
					throw new ArgumentOutOfRangeException("Invalid value for SPCode", value, value.ToString());
				_sPCode = value;
			}
		}

		public virtual string SPMemo
		{
			get { return _sPMemo; }
			set
			{
				if ( value != null && value.Length > 100)
					throw new ArgumentOutOfRangeException("Invalid value for SPMemo", value, value.ToString());
				_sPMemo = value;
			}
		}

		public virtual short SPOrder
		{
			get { return _sPOrder; }
			set { _sPOrder = value; }
		}
		
        public static String SortExpression
        {
            get { return _sortExpression; }
            set { _sortExpression = value; }
        }

        public static SortDirection SortDirection
        {
            get { return _sortDirection; }
            set { _sortDirection = value; }
        }
		#endregion
		
        #region IComparable Methods
        public virtual int CompareTo(object obj)
        {
			if (!(obj is StockPosition))
				throw new InvalidCastException("This object is not of type StockPosition");
			
			int relativeValue;
			switch (SortExpression)
			{
				case "Id":
					relativeValue = this.Id.CompareTo(((StockPosition)obj).Id);
					break;
				case "SPCode":
					relativeValue = this.SPCode.CompareTo(((StockPosition)obj).SPCode);
					break;
				case "SPMemo":
					relativeValue = (this.SPMemo != null) ? this.SPMemo.CompareTo(((StockPosition)obj).SPMemo) : -1;
					break;
				case "SPOrder":
					relativeValue = this.SPOrder.CompareTo(((StockPosition)obj).SPOrder);
					break;
                default:
                    goto case "Id";
			}
            if (StockPosition.SortDirection == SortDirection.Ascending)
				relativeValue *= -1;
			return relativeValue;
		}
		#endregion
	}

	#endregion
}
